{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "66d337ee",
   "metadata": {},
   "source": [
    "## 介绍\n",
    "使用 LlamaIndex 和 NebulaGraph 来构建一个关于费城费利斯队（Philadelphia Phillies）的 RAG 流程\n",
    "\n",
    "跟着这个教程，你将学会\n",
    "- LlamaIndex + Azure 的配置方法\n",
    "- NebulaGraph 服务搭建\n",
    "- 你讲学会 NebulaGraph 的基本使用\n",
    "- NebulaGraph 主要的几种查询方式\n",
    "- NebulaGraph 实战用例及分析\n",
    "\n",
    "## 提前准备\n",
    "- Docker Desktop\n",
    "- Azure OpenAI 或者 GPT-4 （免费的 OpenAPI GPT-3.5 有 token 限制）\n",
    "- python 版本小于 3.12（本项目使用 3.11.6python 版本）\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "23e63d85",
   "metadata": {},
   "source": [
    "## 安装了必要的库\n",
    "\n",
    "除了 LlamaIndex 外，我们还需要安装几个库：\n",
    "- `ipython-ngql`：可以增强你从 Jupyter Notebook 或 iPython 连接到 NebulaGraph 的能力。\n",
    "- `nebula3-python`：用于连接和管理 NebulaGraph 数据库。\n",
    "- `pyvis`：能够使用最少的 Python 代码快速生成可视化网络图。\n",
    "- `networkx`：用于研究图和网络。\n",
    "- `youtube_transcript_api`：这是一个 Python API，允许你获取 YouTube 视频的剧本/字幕。\n",
    "- `openai-whisper`：openAI 提供的语言库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "28c37b8b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: llama_index==0.9.21 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (0.9.21)\n",
      "Requirement already satisfied: ipython-ngql in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (0.7.5)\n",
      "Requirement already satisfied: nebula3-python in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (3.4.0)\n",
      "Requirement already satisfied: pyvis in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (0.3.2)\n",
      "Requirement already satisfied: networkx in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (3.2.1)\n",
      "Requirement already satisfied: youtube_transcript_api in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (0.6.1)\n",
      "Requirement already satisfied: llama-hub in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (0.0.64)\n",
      "Requirement already satisfied: openai-whisper in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (20231117)\n",
      "Requirement already satisfied: pydub in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (0.25.1)\n",
      "Requirement already satisfied: SQLAlchemy>=1.4.49 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from SQLAlchemy[asyncio]>=1.4.49->llama_index==0.9.21) (2.0.23)\n",
      "Requirement already satisfied: aiohttp<4.0.0,>=3.8.6 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama_index==0.9.21) (3.9.1)\n",
      "Requirement already satisfied: beautifulsoup4<5.0.0,>=4.12.2 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama_index==0.9.21) (4.12.2)\n",
      "Requirement already satisfied: dataclasses-json in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama_index==0.9.21) (0.6.3)\n",
      "Requirement already satisfied: deprecated>=1.2.9.3 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama_index==0.9.21) (1.2.14)\n",
      "Requirement already satisfied: fsspec>=2023.5.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama_index==0.9.21) (2023.12.2)\n",
      "Requirement already satisfied: httpx in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama_index==0.9.21) (0.26.0)\n",
      "Requirement already satisfied: nest-asyncio<2.0.0,>=1.5.8 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama_index==0.9.21) (1.5.8)\n",
      "Requirement already satisfied: nltk<4.0.0,>=3.8.1 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama_index==0.9.21) (3.8.1)\n",
      "Requirement already satisfied: numpy in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama_index==0.9.21) (1.26.2)\n",
      "Requirement already satisfied: openai>=1.1.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama_index==0.9.21) (1.21.2)\n",
      "Requirement already satisfied: pandas in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama_index==0.9.21) (2.1.4)\n",
      "Requirement already satisfied: requests>=2.31.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama_index==0.9.21) (2.31.0)\n",
      "Requirement already satisfied: tenacity<9.0.0,>=8.2.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama_index==0.9.21) (8.2.3)\n",
      "Requirement already satisfied: tiktoken>=0.3.3 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama_index==0.9.21) (0.5.2)\n",
      "Requirement already satisfied: typing-extensions>=4.5.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama_index==0.9.21) (4.9.0)\n",
      "Requirement already satisfied: typing-inspect>=0.8.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama_index==0.9.21) (0.9.0)\n",
      "Requirement already satisfied: Jinja2 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from ipython-ngql) (3.1.2)\n",
      "Requirement already satisfied: httplib2>=0.20.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from nebula3-python) (0.22.0)\n",
      "Requirement already satisfied: future>=0.18.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from nebula3-python) (0.18.3)\n",
      "Requirement already satisfied: six>=1.16.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from nebula3-python) (1.16.0)\n",
      "Requirement already satisfied: pytz>=2021.1 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from nebula3-python) (2023.3.post1)\n",
      "Requirement already satisfied: ipython>=5.3.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from pyvis) (8.19.0)\n",
      "Requirement already satisfied: jsonpickle>=1.4.1 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from pyvis) (3.0.2)\n",
      "Requirement already satisfied: html2text in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama-hub) (2020.1.16)\n",
      "Requirement already satisfied: psutil in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama-hub) (5.9.7)\n",
      "Requirement already satisfied: pyaml<24.0.0,>=23.9.7 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama-hub) (23.12.0)\n",
      "Requirement already satisfied: retrying in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from llama-hub) (1.3.4)\n",
      "Requirement already satisfied: numba in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from openai-whisper) (0.58.1)\n",
      "Requirement already satisfied: torch in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from openai-whisper) (2.1.2)\n",
      "Requirement already satisfied: tqdm in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from openai-whisper) (4.66.1)\n",
      "Requirement already satisfied: more-itertools in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from openai-whisper) (10.1.0)\n",
      "Requirement already satisfied: attrs>=17.3.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama_index==0.9.21) (23.1.0)\n",
      "Requirement already satisfied: multidict<7.0,>=4.5 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama_index==0.9.21) (6.0.4)\n",
      "Requirement already satisfied: yarl<2.0,>=1.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama_index==0.9.21) (1.9.4)\n",
      "Requirement already satisfied: frozenlist>=1.1.1 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama_index==0.9.21) (1.4.1)\n",
      "Requirement already satisfied: aiosignal>=1.1.2 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama_index==0.9.21) (1.3.1)\n",
      "Requirement already satisfied: soupsieve>1.2 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from beautifulsoup4<5.0.0,>=4.12.2->llama_index==0.9.21) (2.5)\n",
      "Requirement already satisfied: wrapt<2,>=1.10 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from deprecated>=1.2.9.3->llama_index==0.9.21) (1.16.0)\n",
      "Requirement already satisfied: pyparsing!=3.0.0,!=3.0.1,!=3.0.2,!=3.0.3,<4,>=2.4.2 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from httplib2>=0.20.0->nebula3-python) (3.1.1)\n",
      "Requirement already satisfied: decorator in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from ipython>=5.3.0->pyvis) (5.1.1)\n",
      "Requirement already satisfied: jedi>=0.16 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from ipython>=5.3.0->pyvis) (0.19.1)\n",
      "Requirement already satisfied: matplotlib-inline in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from ipython>=5.3.0->pyvis) (0.1.6)\n",
      "Requirement already satisfied: prompt-toolkit<3.1.0,>=3.0.41 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from ipython>=5.3.0->pyvis) (3.0.43)\n",
      "Requirement already satisfied: pygments>=2.4.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from ipython>=5.3.0->pyvis) (2.17.2)\n",
      "Requirement already satisfied: stack-data in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from ipython>=5.3.0->pyvis) (0.6.2)\n",
      "Requirement already satisfied: traitlets>=5 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from ipython>=5.3.0->pyvis) (5.14.0)\n",
      "Requirement already satisfied: pexpect>4.3 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from ipython>=5.3.0->pyvis) (4.9.0)\n",
      "Requirement already satisfied: MarkupSafe>=2.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from Jinja2->ipython-ngql) (2.1.3)\n",
      "Requirement already satisfied: click in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from nltk<4.0.0,>=3.8.1->llama_index==0.9.21) (8.1.7)\n",
      "Requirement already satisfied: joblib in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from nltk<4.0.0,>=3.8.1->llama_index==0.9.21) (1.3.2)\n",
      "Requirement already satisfied: regex>=2021.8.3 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from nltk<4.0.0,>=3.8.1->llama_index==0.9.21) (2023.12.25)\n",
      "Requirement already satisfied: anyio<5,>=3.5.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from openai>=1.1.0->llama_index==0.9.21) (4.2.0)\n",
      "Requirement already satisfied: distro<2,>=1.7.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from openai>=1.1.0->llama_index==0.9.21) (1.9.0)\n",
      "Requirement already satisfied: pydantic<3,>=1.9.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from openai>=1.1.0->llama_index==0.9.21) (2.5.3)\n",
      "Requirement already satisfied: sniffio in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from openai>=1.1.0->llama_index==0.9.21) (1.3.0)\n",
      "Requirement already satisfied: certifi in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from httpx->llama_index==0.9.21) (2023.11.17)\n",
      "Requirement already satisfied: httpcore==1.* in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from httpx->llama_index==0.9.21) (1.0.2)\n",
      "Requirement already satisfied: idna in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from httpx->llama_index==0.9.21) (3.6)\n",
      "Requirement already satisfied: h11<0.15,>=0.13 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from httpcore==1.*->httpx->llama_index==0.9.21) (0.14.0)\n",
      "Requirement already satisfied: PyYAML in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from pyaml<24.0.0,>=23.9.7->llama-hub) (6.0.1)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from requests>=2.31.0->llama_index==0.9.21) (3.3.2)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from requests>=2.31.0->llama_index==0.9.21) (2.1.0)\n",
      "Requirement already satisfied: greenlet!=0.4.17 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from SQLAlchemy[asyncio]>=1.4.49->llama_index==0.9.21) (3.0.3)\n",
      "Requirement already satisfied: mypy-extensions>=0.3.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from typing-inspect>=0.8.0->llama_index==0.9.21) (1.0.0)\n",
      "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from dataclasses-json->llama_index==0.9.21) (3.20.1)\n",
      "Requirement already satisfied: llvmlite<0.42,>=0.41.0dev0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from numba->openai-whisper) (0.41.1)\n",
      "Requirement already satisfied: python-dateutil>=2.8.2 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from pandas->llama_index==0.9.21) (2.8.2)\n",
      "Requirement already satisfied: tzdata>=2022.1 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from pandas->llama_index==0.9.21) (2023.3)\n",
      "Requirement already satisfied: filelock in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from torch->openai-whisper) (3.13.1)\n",
      "Requirement already satisfied: sympy in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from torch->openai-whisper) (1.12)\n",
      "Requirement already satisfied: parso<0.9.0,>=0.8.3 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from jedi>=0.16->ipython>=5.3.0->pyvis) (0.8.3)\n",
      "Requirement already satisfied: packaging>=17.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from marshmallow<4.0.0,>=3.18.0->dataclasses-json->llama_index==0.9.21) (23.2)\n",
      "Requirement already satisfied: ptyprocess>=0.5 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from pexpect>4.3->ipython>=5.3.0->pyvis) (0.7.0)\n",
      "Requirement already satisfied: wcwidth in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from prompt-toolkit<3.1.0,>=3.0.41->ipython>=5.3.0->pyvis) (0.2.12)\n",
      "Requirement already satisfied: annotated-types>=0.4.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from pydantic<3,>=1.9.0->openai>=1.1.0->llama_index==0.9.21) (0.6.0)\n",
      "Requirement already satisfied: pydantic-core==2.14.6 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from pydantic<3,>=1.9.0->openai>=1.1.0->llama_index==0.9.21) (2.14.6)\n",
      "Requirement already satisfied: executing>=1.2.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from stack-data->ipython>=5.3.0->pyvis) (2.0.1)\n",
      "Requirement already satisfied: asttokens>=2.1.0 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from stack-data->ipython>=5.3.0->pyvis) (2.4.1)\n",
      "Requirement already satisfied: pure-eval in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from stack-data->ipython>=5.3.0->pyvis) (0.2.2)\n",
      "Requirement already satisfied: mpmath>=0.19 in /Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages (from sympy->torch->openai-whisper) (1.3.0)\n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    }
   ],
   "source": [
    "%pip install llama_index==0.9.21 ipython-ngql nebula3-python pyvis networkx youtube_transcript_api llama-hub openai-whisper pydub"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7abe717c",
   "metadata": {},
   "source": [
    "### 调整输出日志配置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "01202746",
   "metadata": {},
   "outputs": [],
   "source": [
    "import logging\n",
    "import sys\n",
    "\n",
    "logging.basicConfig(\n",
    "    stream=sys.stdout, level=logging.INFO\n",
    ")  # logging.DEBUG for more verbose output\n",
    "logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1fc97cc",
   "metadata": {},
   "source": [
    "## 连接到 NebulaGraph 并设置新空间\n",
    "[NebulaGraph 安装文档](https://docs.nebula-graph.io/3.6.0/2.quick-start/1.quick-start-workflow/) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "7eadf711",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Connection Pool Created\n",
      "INFO:nebula3.logger:Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>demo_basketballplayer</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>phillies_rag</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    Name\n",
       "0  demo_basketballplayer\n",
       "1           phillies_rag"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "\n",
    "import os\n",
    "os.environ[\"GRAPHD_HOST\"] = \"127.0.0.1\"\n",
    "os.environ[\"NEBULA_USER\"] = \"root\"\n",
    "os.environ[\"NEBULA_PASSWORD\"] = \"nebula\" \n",
    "os.environ[\"NEBULA_ADDRESS\"] = \"127.0.0.1:9669\"  \n",
    "\n",
    "%reload_ext ngql\n",
    "connection_string = f\"--address {os.environ['GRAPHD_HOST']} --port 9669 --user root --password {os.environ['NEBULA_PASSWORD']}\"\n",
    "%ngql {connection_string}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "5892a781",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:nebula3.logger:Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: []\n",
       "Index: []"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%ngql CREATE SPACE IF NOT EXISTS phillies_rag(vid_type=FIXED_STRING(256), partition_num=1, replica_factor=1);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "fa1742de",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:nebula3.logger:Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>demo_basketballplayer</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>phillies_rag</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    Name\n",
       "0  demo_basketballplayer\n",
       "1           phillies_rag"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%ngql SHOW SPACES;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "7dfd6fa3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:nebula3.logger:Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: []\n",
       "Index: []"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%ngql\n",
    "USE phillies_rag;\n",
    "CREATE TAG IF NOT EXISTS entity(name string);\n",
    "CREATE EDGE IF NOT EXISTS relationship(relationship string);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "879761b9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:nebula3.logger:Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: []\n",
       "Index: []"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%ngql CREATE TAG INDEX IF NOT EXISTS entity_index ON entity(name(256));"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ff0764d7",
   "metadata": {},
   "source": [
    "### 构建 NebulaGraphStore"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "9275b914",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.storage.storage_context import StorageContext\n",
    "from llama_index.graph_stores import NebulaGraphStore\n",
    "\n",
    "space_name = \"phillies_rag\"\n",
    "edge_types, rel_prop_names = [\"relationship\"], [\"relationship\"]\n",
    "tags = [\"entity\"]\n",
    "\n",
    "graph_store = NebulaGraphStore(\n",
    "    space_name=space_name,\n",
    "    edge_types=edge_types,\n",
    "    rel_prop_names=rel_prop_names,\n",
    "    tags=tags,\n",
    ")\n",
    "storage_context = StorageContext.from_defaults(graph_store=graph_store)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "ed5b713e",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "space_name = \"phillies_rag\"\n",
    "edge_types, rel_prop_names = [\"relationship\"], [\"relationship\"]\n",
    "tags = [\"entity\"]\n",
    "\n",
    "graph_store = NebulaGraphStore(\n",
    "    space_name=space_name,\n",
    "    edge_types=edge_types,\n",
    "    rel_prop_names=rel_prop_names,\n",
    "    tags=tags,\n",
    ")\n",
    "storage_context = StorageContext.from_defaults(graph_store=graph_store)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "208852a5",
   "metadata": {},
   "source": [
    "## 加载数据并创建 KG 索引"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bbecab75",
   "metadata": {},
   "source": [
    "### OpenAI GPT 配置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "3d650799",
   "metadata": {},
   "outputs": [],
   "source": [
    "# import os\n",
    "# os.environ[\"OPENAI_API_KEY\"] = \"sk-xxx\"\n",
    "# from llama_index import (\n",
    "#     LLMPredictor,\n",
    "#     ServiceContext,\n",
    "#     KnowledgeGraphIndex,\n",
    "#     SimpleDirectoryReader,\n",
    "# )\n",
    "# from llama_index.graph_stores import SimpleGraphStore\n",
    "# from llama_index import download_loader\n",
    "# from llama_index.llms import OpenAI\n",
    "\n",
    "# # define LLM\n",
    "# llm = OpenAI(temperature=0.1, model=\"gpt-3.5-turbo\")\n",
    "# service_context = ServiceContext.from_defaults(llm=llm, chunk_size=512)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ccc46a56",
   "metadata": {},
   "source": [
    "### Azure OpenAI 配置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "2be708ee",
   "metadata": {},
   "outputs": [],
   "source": [
    "# For Azure OpenAI\n",
    "from llama_index.llms import AzureOpenAI\n",
    "from llama_index.embeddings import AzureOpenAIEmbedding\n",
    "from llama_index import (\n",
    "    VectorStoreIndex,\n",
    "    SimpleDirectoryReader,\n",
    "    KnowledgeGraphIndex,\n",
    "    ServiceContext,\n",
    ")\n",
    "\n",
    "from llama_index.storage.storage_context import StorageContext\n",
    "\n",
    "import logging\n",
    "import sys\n",
    "\n",
    "from IPython.display import Markdown, display\n",
    "\n",
    "logging.basicConfig(\n",
    "    stream=sys.stdout, level=logging.INFO\n",
    ")  # logging.DEBUG for more verbose output\n",
    "logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))\n",
    "\n",
    "api_key = os.environ[\"AZURE_OPENAI_KEY\"]\n",
    "azure_endpoint = os.getenv(\"AZURE_OPENAI_ENDPOINT\")\n",
    "api_version = \"2023-09-01-preview\"\n",
    "\n",
    "llm = AzureOpenAI(\n",
    "    model=\"gpt-35-turbo-16k\",\n",
    "    deployment_name=\"gpt-35-turbo-16k\",\n",
    "    api_key=api_key,\n",
    "    azure_endpoint=azure_endpoint,\n",
    "    api_version=api_version,\n",
    ")\n",
    "\n",
    "# You need to deploy your own embedding model as well as your own chat completion model\n",
    "embed_model = AzureOpenAIEmbedding(\n",
    "    model=\"text-embedding-ada-002\",\n",
    "    deployment_name=\"text-embedding-ada-002\",\n",
    "    api_key=api_key,\n",
    "    azure_endpoint=azure_endpoint,\n",
    "    api_version=api_version,\n",
    ")\n",
    "\n",
    "\n",
    "service_context = ServiceContext.from_defaults(\n",
    "    llm=llm,\n",
    "    embed_model=embed_model,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "cb727e26",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:llama_index.indices.loading:Loading all indices.\n",
      "Loading all indices.\n",
      "Loading all indices.\n",
      "Loading all indices.\n",
      "Loading all indices.\n",
      "Loading all indices.\n",
      "Loading all indices.\n",
      "Loading all indices.\n",
      "Loading all indices.\n",
      "Loading all indices.\n",
      "Loading all indices.\n"
     ]
    }
   ],
   "source": [
    "from llama_index import load_index_from_storage\n",
    "from llama_hub.youtube_transcript import YoutubeTranscriptReader\n",
    "from llama_index import download_loader\n",
    "\n",
    "try:\n",
    "\n",
    "    storage_context = StorageContext.from_defaults(persist_dir='./storage_graph', graph_store=graph_store)\n",
    "    kg_index = load_index_from_storage(\n",
    "        storage_context=storage_context,\n",
    "        service_context=service_context,\n",
    "        max_triplets_per_chunk=15,\n",
    "        space_name=space_name,\n",
    "        edge_types=edge_types,\n",
    "        rel_prop_names=rel_prop_names,\n",
    "        tags=tags,\n",
    "        verbose=True,\n",
    "    )\n",
    "    index_loaded = True\n",
    "except:\n",
    "    index_loaded = False\n",
    "\n",
    "if not index_loaded:\n",
    "    # 获取在线网站文档数据和视频数据\n",
    "    WikipediaReader = download_loader(\"WikipediaReader\")\n",
    "    loader = WikipediaReader()\n",
    "    wiki_documents = loader.load_data(pages=['Philadelphia Phillies'], auto_suggest=False)\n",
    "    print(f'Loaded {len(wiki_documents)} documents')\n",
    "\n",
    "    # 在线获取视频需要验证，我们将视频下载到 graph_data 文件夹\n",
    "    # youtube_loader = YoutubeTranscriptReader()\n",
    "    # youtube_documents = youtube_loader.load_data(ytlinks=['https://www.youtube.com/watch?v=k-HTQ8T7oVw'])    \n",
    "    # print(f'Loaded {len(youtube_documents)} YouTube documents')\n",
    "\n",
    "    kg_index = KnowledgeGraphIndex.from_documents(\n",
    "        # documents=wiki_documents + youtube_documents,\n",
    "        documents=wiki_documents + SimpleDirectoryReader(\n",
    "            \"./graph_data\"\n",
    "        ).load_data() ,\n",
    "        storage_context=storage_context,\n",
    "        max_triplets_per_chunk=15,\n",
    "        service_context=service_context,\n",
    "        space_name=space_name,\n",
    "        edge_types=edge_types,\n",
    "        rel_prop_names=rel_prop_names,\n",
    "        tags=tags,\n",
    "        include_embeddings=True,\n",
    "    )\n",
    "    \n",
    "    kg_index.storage_context.persist(persist_dir='./storage_graph')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6769d53",
   "metadata": {},
   "source": [
    "## 运行查询 NebulaGraph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "1e1d23f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.query_engine import KnowledgeGraphQueryEngine\n",
    "from llama_index.storage.storage_context import StorageContext\n",
    "from llama_index.graph_stores import NebulaGraphStore\n",
    "from IPython.display import Markdown, display\n",
    "\n",
    "# query_engine = KnowledgeGraphQueryEngine(\n",
    "#     storage_context=storage_context,\n",
    "#     service_context=service_context,\n",
    "#     llm=llm,\n",
    "#     verbose=True,\n",
    "# )\n",
    "\n",
    "hybrid_query_engine = kg_index.as_query_engine(\n",
    "    include_text=True,\n",
    "    response_mode=\"tree_summarize\",\n",
    "    embedding_mode=\"hybrid\",\n",
    "    similarity_top_k=3,\n",
    "    explore_global_knowledge=True,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "c8410735",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>Bryce Harper is a well-known baseball player who has achieved significant success in his career. He has won the World Series and has been selected as an All-Star multiple times. Harper is also recognized as a one-time silver slugger. He is known for his exceptional skills and is considered one of the top players in Major League Baseball. Additionally, Harper has received lucrative contracts from both the Philadelphia Phillies and the Los Angeles Dodgers, further highlighting his value and talent in the sport.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "hybrid_query_engine = kg_index.as_query_engine()\n",
    "response = hybrid_query_engine.query(\"Tell me about Bryce Harper.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "de7326cc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>Bryce Harper is a well-known baseball player who has achieved significant success in his career. He has won the World Series and has been selected as an All-Star multiple times. Harper is also recognized for his offensive abilities, as he has been awarded the Silver Slugger and has received contracts from both the Philadelphia Phillies and the Los Angeles Dodgers. His performance on the field and his popularity among baseball fans have made him a prominent figure in the sport.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "query_engine = kg_index.as_query_engine()\n",
    "response = query_engine.query(\"Tell me about Bryce Harper.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "09923bdf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>Bryce Harper is a well-known baseball player who has achieved significant success in his career. He has won the World Series and has been selected as an All-Star multiple times. Harper is also recognized as a one-time silver slugger. He is known for his exceptional skills and is considered one of the top players in Major League Baseball. Additionally, Harper has received lucrative contracts from both the Philadelphia Phillies and the Los Angeles Dodgers, solidifying his status as one of the highest-paid players in the league.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = query_engine.query(\"Tell me about Bryce Harper.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "b4b199aa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:nebula3.logger:Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>p</th>\n",
       "      <th>e</th>\n",
       "      <th>m</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [p, e, m]\n",
       "Index: []"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%ngql\n",
    "MATCH (p:`entity`)-[e:relationship]->(m:`entity`)\n",
    "  WHERE p.`entity`.`name` == 'Bryce Harper'\n",
    "RETURN p, e, m;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "904a738a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "        <iframe\n",
       "            width=\"100%\"\n",
       "            height=\"500px\"\n",
       "            src=\"nebulagraph.html\"\n",
       "            frameborder=\"0\"\n",
       "            allowfullscreen\n",
       "            \n",
       "        ></iframe>\n",
       "        "
      ],
      "text/plain": [
       "<IPython.lib.display.IFrame at 0x173af0590>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<class 'pyvis.network.Network'> |N|=0 |E|=0"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%ng_draw"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "37d83dc0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>The standing ovation that Trey Turner received had a significant impact on his season. It provided him with a tremendous amount of support and love from the fans, which helped him regain his confidence and mental focus. After the standing ovation, Trey Turner had one of his best games in weeks and continued to perform at a high level in the following games. He experienced a significant improvement in his batting average, home runs, and RBIs. The love and support shown by the fans seemed to have lifted the weight off his shoulders and allowed him to play the game with more happiness and relaxation. Overall, the standing ovation played a crucial role in changing Trey Turner's season for the better.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = query_engine.query(\"How did the standing ovation Trey Turner received change his season?\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "fd3f50b0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:nebula3.logger:Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>p</th>\n",
       "      <th>r</th>\n",
       "      <th>q</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>(\"Trey Turner\" :entity{name: \"Trey Turner\"})</td>\n",
       "      <td>(\"Trey Turner\")-[:relationship@-88459676706300...</td>\n",
       "      <td>(\"a World Series\" :entity{name: \"a World Serie...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>(\"Trey Turner\" :entity{name: \"Trey Turner\"})</td>\n",
       "      <td>(\"Trey Turner\")-[:relationship@-88459676706300...</td>\n",
       "      <td>(\"the World Series\" :entity{name: \"the World S...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>(\"Trey Turner\" :entity{name: \"Trey Turner\"})</td>\n",
       "      <td>(\"Trey Turner\")-[:relationship@-86252438187619...</td>\n",
       "      <td>(\"nightmare season\" :entity{name: \"nightmare s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>(\"Trey Turner\" :entity{name: \"Trey Turner\"})</td>\n",
       "      <td>(\"Trey Turner\")-[:relationship@-86252438187619...</td>\n",
       "      <td>(\"on MLB first and second team\" :entity{name: ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>(\"Trey Turner\" :entity{name: \"Trey Turner\"})</td>\n",
       "      <td>(\"Trey Turner\")-[:relationship@-86252438187619...</td>\n",
       "      <td>(\"silver slugger\" :entity{name: \"silver slugge...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>(\"Trey Turner\" :entity{name: \"Trey Turner\"})</td>\n",
       "      <td>(\"Trey Turner\")-[:relationship@662731478172054...</td>\n",
       "      <td>(\"two-time all-star\" :entity{name: \"two-time a...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>(\"Trey Turner\" :entity{name: \"Trey Turner\"})</td>\n",
       "      <td>(\"Trey Turner\")-[:relationship@776539795941827...</td>\n",
       "      <td>(\"the all-time MLB record\" :entity{name: \"the ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>(\"Trey Turner\" :entity{name: \"Trey Turner\"})</td>\n",
       "      <td>(\"Trey Turner\")-[:relationship@781885191856417...</td>\n",
       "      <td>(\"what happened to Trey Turner\" :entity{name: ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>68</th>\n",
       "      <td>(\"Trey Turner\" :entity{name: \"Trey Turner\"})</td>\n",
       "      <td>(\"Trey Turner\")-[:relationship@796052197484922...</td>\n",
       "      <td>(\"all-time MLB record\" :entity{name: \"all-time...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69</th>\n",
       "      <td>(\"Trey Turner\" :entity{name: \"Trey Turner\"})</td>\n",
       "      <td>(\"Trey Turner\")-[:relationship@855513318978384...</td>\n",
       "      <td>(\"8th hole\" :entity{name: \"8th hole\"})</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>70 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                               p  \\\n",
       "0   (\"Trey Turner\" :entity{name: \"Trey Turner\"})   \n",
       "1   (\"Trey Turner\" :entity{name: \"Trey Turner\"})   \n",
       "2   (\"Trey Turner\" :entity{name: \"Trey Turner\"})   \n",
       "3   (\"Trey Turner\" :entity{name: \"Trey Turner\"})   \n",
       "4   (\"Trey Turner\" :entity{name: \"Trey Turner\"})   \n",
       "..                                           ...   \n",
       "65  (\"Trey Turner\" :entity{name: \"Trey Turner\"})   \n",
       "66  (\"Trey Turner\" :entity{name: \"Trey Turner\"})   \n",
       "67  (\"Trey Turner\" :entity{name: \"Trey Turner\"})   \n",
       "68  (\"Trey Turner\" :entity{name: \"Trey Turner\"})   \n",
       "69  (\"Trey Turner\" :entity{name: \"Trey Turner\"})   \n",
       "\n",
       "                                                    r  \\\n",
       "0   (\"Trey Turner\")-[:relationship@-88459676706300...   \n",
       "1   (\"Trey Turner\")-[:relationship@-88459676706300...   \n",
       "2   (\"Trey Turner\")-[:relationship@-86252438187619...   \n",
       "3   (\"Trey Turner\")-[:relationship@-86252438187619...   \n",
       "4   (\"Trey Turner\")-[:relationship@-86252438187619...   \n",
       "..                                                ...   \n",
       "65  (\"Trey Turner\")-[:relationship@662731478172054...   \n",
       "66  (\"Trey Turner\")-[:relationship@776539795941827...   \n",
       "67  (\"Trey Turner\")-[:relationship@781885191856417...   \n",
       "68  (\"Trey Turner\")-[:relationship@796052197484922...   \n",
       "69  (\"Trey Turner\")-[:relationship@855513318978384...   \n",
       "\n",
       "                                                    q  \n",
       "0   (\"a World Series\" :entity{name: \"a World Serie...  \n",
       "1   (\"the World Series\" :entity{name: \"the World S...  \n",
       "2   (\"nightmare season\" :entity{name: \"nightmare s...  \n",
       "3   (\"on MLB first and second team\" :entity{name: ...  \n",
       "4   (\"silver slugger\" :entity{name: \"silver slugge...  \n",
       "..                                                ...  \n",
       "65  (\"two-time all-star\" :entity{name: \"two-time a...  \n",
       "66  (\"the all-time MLB record\" :entity{name: \"the ...  \n",
       "67  (\"what happened to Trey Turner\" :entity{name: ...  \n",
       "68  (\"all-time MLB record\" :entity{name: \"all-time...  \n",
       "69             (\"8th hole\" :entity{name: \"8th hole\"})  \n",
       "\n",
       "[70 rows x 3 columns]"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%ngql \n",
    "MATCH (p:`entity`)-[r:`relationship`]->(q:`entity`)\n",
    "WHERE p.`entity`.`name` == 'Trey Turner' \n",
    "RETURN p, r, q;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "e3c2c933",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "        <iframe\n",
       "            width=\"100%\"\n",
       "            height=\"500px\"\n",
       "            src=\"nebulagraph.html\"\n",
       "            frameborder=\"0\"\n",
       "            allowfullscreen\n",
       "            \n",
       "        ></iframe>\n",
       "        "
      ],
      "text/plain": [
       "<IPython.lib.display.IFrame at 0x17462d310>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<class 'pyvis.network.Network'> |N|=46 |E|=70"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%ng_draw"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "a9e67884",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>The Philadelphia Phillies have signed Trey Turner to a $300 million contract. They also signed Nick Cassianos to a big deal last year, but he struggled in his first season. The team has coaches, staff, and teammates who have full belief in Turner's ability to bounce back.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = query_engine.query(\"Tell me about some of the facts of Philadelphia Phillies.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "d1144d69",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:nebula3.logger:Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n",
      "Get connection to ('127.0.0.1', 9669)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>p</th>\n",
       "      <th>e</th>\n",
       "      <th>m</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [p, e, m]\n",
       "Index: []"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%ngql \n",
    "MATCH (p:`entity`)-[e:relationship]->(m:`entity`)\n",
    "  WHERE p.`entity`.`name` == 'Philadelphia Phillies' \n",
    "RETURN p, e, m;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "f564e410",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "        <iframe\n",
       "            width=\"100%\"\n",
       "            height=\"500px\"\n",
       "            src=\"nebulagraph.html\"\n",
       "            frameborder=\"0\"\n",
       "            allowfullscreen\n",
       "            \n",
       "        ></iframe>\n",
       "        "
      ],
      "text/plain": [
       "<IPython.lib.display.IFrame at 0x174708e50>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<class 'pyvis.network.Network'> |N|=0 |E|=0"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%ng_draw"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "110773e3",
   "metadata": {},
   "source": [
    "## 使用矢量索引进行查询"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "3f61f5f1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Loaded 1 documents\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages/whisper/transcribe.py:115: UserWarning: FP16 is not supported on CPU; using FP32 instead\n",
      "  warnings.warn(\"FP16 is not supported on CPU; using FP32 instead\")\n",
      "/Users/minp/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages/whisper/transcribe.py:115: UserWarning: FP16 is not supported on CPU; using FP32 instead\n",
      "  warnings.warn(\"FP16 is not supported on CPU; using FP32 instead\")\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>Bryce Harper is a professional baseball player who has played for the Philadelphia Phillies since the 2019 season. He was signed to a 13-year, $330 million deal, making it a significant acquisition for the team. Harper has been a standout player for the Phillies and was named the NL Most Valuable Player for the 2021 season. He has been a key contributor to the team's success, including their first winning season since 2011 and their playoff run in 2022, where they reached the World Series.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from llama_index import VectorStoreIndex\n",
    "\n",
    "WikipediaReader = download_loader(\"WikipediaReader\")\n",
    "loader = WikipediaReader()\n",
    "wiki_documents = loader.load_data(pages=['Philadelphia Phillies'], auto_suggest=False)\n",
    "print(f'Loaded {len(wiki_documents)} documents')\n",
    "\n",
    "# youtube_loader = YoutubeTranscriptReader()\n",
    "# youtube_documents = youtube_loader.load_data(ytlinks=['https://www.youtube.com/watch?v=k-HTQ8T7oVw'])    \n",
    "# print(f'Loaded {len(youtube_documents)} YouTube documents')\n",
    "\n",
    "vector_index = VectorStoreIndex.from_documents(\n",
    "    # documents=wiki_documents + youtube_documents,\n",
    "    documents=wiki_documents + SimpleDirectoryReader(\"./graph_data\").load_data() ,\n",
    "    service_context=service_context,\n",
    ")\n",
    "vector_query_engine = vector_index.as_query_engine()\n",
    "\n",
    "response = vector_query_engine.query(\"Tell me about Bryce Harper.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "02a51d42",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>The standing ovation Trey Turner received seemed to have a positive impact on his season. After receiving the ovation, Turner had one of his best games in weeks and felt that the hit he got during the game was one of his best swings all year. Following the ovation, Turner's performance improved significantly, with a batting average of .343, an OPS over a thousand, and several hits, home runs, and RBIs in the 18 games that followed. The love and support shown by the fans seemed to have boosted Turner's confidence and helped him get out of his own head, allowing him to play the game more relaxed and happier.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = vector_query_engine.query(\"How did the standing ovation Trey Turner received change his season?\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "2b9eb77d",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>The Philadelphia Phillies are a professional baseball team based in Philadelphia. They compete in Major League Baseball as a member of the National League East Division. The team's home stadium is Citizens Bank Park, located in the South Philadelphia Sports Complex. The Phillies have a history dating back to 1883 and are the oldest, continuous, one-name, one-city franchise in all of professional sports. They have won two World Series championships, eight National League pennants, and have made 15 playoff appearances. The team has played at several stadiums in Philadelphia, including Recreation Park, Baker Bowl, Shibe Park (later renamed Connie Mack Stadium), Veterans Stadium, and now Citizens Bank Park. The Phillies have a loyal fan base and have had both successes and challenges throughout their history.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = vector_query_engine.query(\"Tell me about some of the facts of Philadelphia Phillies.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "61fb291e",
   "metadata": {},
   "source": [
    "## 自定义组合查询引擎（KG 检索器和向量索引检索器的组合）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "f273884b",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index import QueryBundle\n",
    "from llama_index.schema import NodeWithScore\n",
    "from llama_index.retrievers import BaseRetriever, VectorIndexRetriever, KGTableRetriever\n",
    "from typing import List\n",
    "\n",
    "class CustomRetriever(BaseRetriever):\n",
    "    \"\"\"Custom retriever that performs both Vector search and Knowledge Graph search\"\"\"\n",
    "\n",
    "    def __init__(\n",
    "        self,\n",
    "        vector_retriever: VectorIndexRetriever,\n",
    "        kg_retriever: KGTableRetriever,\n",
    "        mode: str = \"OR\",\n",
    "    ) -> None:\n",
    "        \"\"\"Init params.\"\"\"\n",
    "\n",
    "        self._vector_retriever = vector_retriever\n",
    "        self._kg_retriever = kg_retriever\n",
    "        if mode not in (\"AND\", \"OR\"):\n",
    "            raise ValueError(\"Invalid mode.\")\n",
    "        self._mode = mode\n",
    "\n",
    "    def _retrieve(self, query_bundle: QueryBundle) -> List[NodeWithScore]:\n",
    "        \"\"\"Retrieve nodes given query.\"\"\"\n",
    "\n",
    "        vector_nodes = self._vector_retriever.retrieve(query_bundle)\n",
    "        kg_nodes = self._kg_retriever.retrieve(query_bundle)\n",
    "\n",
    "        vector_ids = {n.node.node_id for n in vector_nodes}\n",
    "        kg_ids = {n.node.node_id for n in kg_nodes}\n",
    "\n",
    "        combined_dict = {n.node.node_id: n for n in vector_nodes}\n",
    "        combined_dict.update({n.node.node_id: n for n in kg_nodes})\n",
    "\n",
    "        if self._mode == \"AND\":\n",
    "            retrieve_ids = vector_ids.intersection(kg_ids)\n",
    "        else:\n",
    "            retrieve_ids = vector_ids.union(kg_ids)\n",
    "\n",
    "        retrieve_nodes = [combined_dict[rid] for rid in retrieve_ids]\n",
    "        return retrieve_nodes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "f28c06f8",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index import get_response_synthesizer\n",
    "from llama_index.query_engine import RetrieverQueryEngine\n",
    "from llama_index.retrievers import VectorIndexRetriever, KGTableRetriever\n",
    "\n",
    "# create custom retriever\n",
    "vector_retriever = VectorIndexRetriever(index=vector_index)\n",
    "kg_retriever = KGTableRetriever(\n",
    "    index=kg_index, retriever_mode=\"keyword\", include_text=False\n",
    ")\n",
    "custom_retriever = CustomRetriever(vector_retriever, kg_retriever)\n",
    "\n",
    "# create response synthesizer\n",
    "response_synthesizer = get_response_synthesizer(\n",
    "    service_context=service_context,\n",
    "    response_mode=\"tree_summarize\",\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0058aba5",
   "metadata": {},
   "source": [
    "## 探索七种查询方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "8c5faed8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# KG vector-based entity retrieval\n",
    "kg_query_engine = kg_index.as_query_engine()\n",
    "\n",
    "# KG keyword-based entity retrieval\n",
    "kg_keyword_query_engine = kg_index.as_query_engine(\n",
    "    # setting to false uses the raw triplets instead of adding the text from the corresponding nodes\n",
    "    include_text=False,\n",
    "    retriever_mode=\"keyword\",\n",
    "    response_mode=\"tree_summarize\",\n",
    ")\n",
    "\n",
    "# KG hybrid entity retrieval\n",
    "kg_hybrid_query_engine = kg_index.as_query_engine(\n",
    "    include_text=True,\n",
    "    response_mode=\"tree_summarize\",\n",
    "    embedding_mode=\"hybrid\",\n",
    "    similarity_top_k=3,\n",
    "    explore_global_knowledge=True,\n",
    ")\n",
    "\n",
    "# Raw vector index retrieval\n",
    "vector_query_engine = vector_index.as_query_engine()\n",
    "\n",
    "# Custom combo query engine\n",
    "custom_query_engine = RetrieverQueryEngine(\n",
    "    retriever=custom_retriever,\n",
    "    response_synthesizer=response_synthesizer,\n",
    ")\n",
    "\n",
    "# using KnowledgeGraphQueryEngine\n",
    "from llama_index.query_engine import KnowledgeGraphQueryEngine\n",
    "\n",
    "kgqe_query_engine = KnowledgeGraphQueryEngine(\n",
    "    storage_context=storage_context,\n",
    "    service_context=service_context,\n",
    "    llm=llm,\n",
    "    verbose=True,\n",
    ")\n",
    "\n",
    "# using KnowledgeGraphRAGRetriever\n",
    "from llama_index.query_engine import RetrieverQueryEngine\n",
    "from llama_index.retrievers import KnowledgeGraphRAGRetriever\n",
    "\n",
    "graph_rag_retriever = KnowledgeGraphRAGRetriever(\n",
    "    storage_context=storage_context,\n",
    "    service_context=service_context,\n",
    "    llm=llm,\n",
    "    verbose=True,\n",
    ")\n",
    "\n",
    "kg_rag_query_engine = RetrieverQueryEngine.from_args(\n",
    "    graph_rag_retriever, service_context=service_context\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "07739d4a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>Bryce Harper is a well-known baseball player who has achieved significant success in his career. He has won the World Series, been a two-time All-Star, and has received contracts from both the Philadelphia Phillies and the Los Angeles Dodgers. Harper is highly regarded by baseball fans and is considered one of the top players in the sport.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = kg_query_engine.query(\"Tell me about Bryce Harper.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "99889510",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>Bryce Harper is a well-known figure, but without any specific relationships mentioned in the context information, it is difficult to provide a detailed answer about him. However, Bryce Harper is a professional baseball player who has gained recognition for his skills and achievements in the sport. He has played for the Washington Nationals and the Philadelphia Phillies in Major League Baseball. Harper is known for his powerful hitting, speed, and overall athleticism. He has been named an All-Star multiple times and has won various awards throughout his career.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = kg_keyword_query_engine.query(\"Tell me about Bryce Harper.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "6be9dd39",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: cce2d708-5e68-4d30-a06b-aa0d0c869421: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: cce2d708-5e68-4d30-a06b-aa0d0c869421: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: cce2d708-5e68-4d30-a06b-aa0d0c869421: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: cce2d708-5e68-4d30-a06b-aa0d0c869421: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: cce2d708-5e68-4d30-a06b-aa0d0c869421: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: cce2d708-5e68-4d30-a06b-aa0d0c869421: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: cce2d708-5e68-4d30-a06b-aa0d0c869421: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: cce2d708-5e68-4d30-a06b-aa0d0c869421: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: cce2d708-5e68-4d30-a06b-aa0d0c869421: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: cce2d708-5e68-4d30-a06b-aa0d0c869421: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: cce2d708-5e68-4d30-a06b-aa0d0c869421: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>I'm sorry, but there is no information provided about Bryce Harper in the given context.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = kg_hybrid_query_engine.query(\"Tell me about Bryce Harper.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "e066b6de",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>Bryce Harper is a professional baseball player who has played for the Philadelphia Phillies since the 2019 season. He was signed to a 13-year, $330 million deal, making him one of the highest-paid players in the league. Harper has been a key player for the Phillies and has had several notable achievements, including winning the NL Most Valuable Player Award for the 2021 season. He has been a significant contributor to the team's success, helping them reach the playoffs in the 2022 season and advancing to the World Series.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = vector_query_engine.query(\"Tell me about Bryce Harper.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "78d51472",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>Bryce Harper is a professional baseball player who has played for the Philadelphia Phillies since the 2019 season. He was signed to a 13-year, $330 million deal, which was a significant move for the Phillies during the offseason. Harper has been a standout player for the team and was named the NL Most Valuable Player for the 2021 season. He has been a key part of the Phillies' lineup and has helped improve the team's performance. Harper's contributions have been recognized, and he has played a crucial role in the Phillies' success, including their playoff run in the 2022 season.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = custom_query_engine.query(\"Tell me about Bryce Harper.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "0ca895ec",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "\u001b[1;3;33mGraph Store Query:\n",
      "MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Bryce Harper'\n",
      "RETURN e.`entity`.`name`\n",
      "\u001b[0m\u001b[1;3;33mGraph Store Response:\n",
      "{'e.entity.name': []}\n",
      "\u001b[0mINFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "\u001b[1;3;32mFinal Response: Bryce Harper is not mentioned in the graph database.\n",
      "\u001b[0m"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>Bryce Harper is not mentioned in the graph database.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = kgqe_query_engine.query(\"Tell me about Bryce Harper.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "c851231d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "\u001b[1;3;32mEntities processed: ['Bryce Harper', 'Harper', 'Bryce']\n",
      "\u001b[0mINFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "\u001b[1;3;32mEntities processed: ['Bryce Harper', 'Harper', 'Bryce']\n",
      "\u001b[0mINFO:llama_index.indices.knowledge_graph.retrievers:> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>Empty Response</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = kg_rag_query_engine.query(\"Tell me about Bryce Harper.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "8f24ea88",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>The standing ovation that Trey Turner received had a significant impact on his season. It provided him with a tremendous amount of support and love from the fans, which helped him regain his confidence and mental focus. After the standing ovation, Trey Turner had one of his best games in weeks and continued to perform at a high level in the following games. He experienced a significant improvement in his batting average, home runs, and RBIs. The love and support shown by the fans seemed to have lifted the weight off his shoulders and allowed him to play the game with more happiness and relaxation. Overall, the standing ovation played a crucial role in changing Trey Turner's season and helping him overcome his struggles.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = kg_query_engine.query(\"How did the standing ovation Trey Turner received change his season?\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "9f2b9d5a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>The standing ovation Trey Turner received likely had a positive impact on his season. It may have boosted his confidence and morale, leading to improved performance on the field. The support and appreciation from the fans could have motivated him to overcome any challenges or struggles he was facing, potentially resulting in a turnaround in his season.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = kg_keyword_query_engine.query(\"How did the standing ovation Trey Turner received change his season?\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "e7f0ac92",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>The standing ovation that Trey Turner received had a significant impact on his season. It provided him with a boost of confidence and support from the fans, which helped him overcome his struggles. After the standing ovation, Trey Turner had one of his best games in weeks and his performance improved significantly. In the 18 games since the standing ovation, he has been batting .343 with a batting average, an OPS over a thousand, and impressive stats in hits, home runs, and RBIs. The love and support shown by the fans through the standing ovation seemed to have changed Trey Turner's mindset and helped him regain his form.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = kg_hybrid_query_engine.query(\"How did the standing ovation Trey Turner received change his season?\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "9b9d54a9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>The standing ovation Trey Turner received seemed to have a positive impact on his season. After receiving the ovation, Turner had one of his best games in weeks and felt that the hit he got during that game was one of his best swings all year. Following the ovation, Turner's performance improved significantly, with a batting average of .343, an OPS over 1.000, and several hits, home runs, and RBIs in the subsequent 18 games. The love and support shown by the fans seemed to have lifted Turner's spirits and helped him regain confidence, leading to a turnaround in his performance.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = vector_query_engine.query(\"How did the standing ovation Trey Turner received change his season?\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "46aeefec",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>The standing ovation that Trey Turner received had a positive impact on his season. After receiving the ovation, Trey seemed happier, more relaxed, and out of his own head. He had one of his best games in weeks and felt that the hit he got during the game was one of his best swings all year. In the 18 games since the standing ovation, Trey has been performing exceptionally well, with a batting average of .343, an OPS over a thousand, and impressive stats in hits, home runs, and RBIs. It seems that the love and support shown by the fans through the standing ovation had a significant effect on Trey's performance and helped him bounce back from his struggles.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = custom_query_engine.query(\"How did the standing ovation Trey Turner received change his season?\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "326e10a5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-09-01-preview \"HTTP/1.1 200 OK\"\n",
      "\u001b[1;3;33mGraph Store Query:\n",
      "MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`\n",
      "\u001b[0mERROR:llama_index.graph_stores.nebulagraph:Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "ERROR:llama_index.graph_stores.nebulagraph:Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "ERROR:llama_index.graph_stores.nebulagraph:Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n",
      "Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\n",
      "WHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\n",
      "SET p.`entity`.`season` = p.`entity`.`season` + 1\n",
      "RETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'\n"
     ]
    },
    {
     "ename": "RetryError",
     "evalue": "RetryError[<Future at 0x317f75710 state=finished raised ValueError>]",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "File \u001b[0;32m~/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages/tenacity/__init__.py:382\u001b[0m, in \u001b[0;36mRetrying.__call__\u001b[0;34m(self, fn, *args, **kwargs)\u001b[0m\n\u001b[1;32m    381\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 382\u001b[0m     result \u001b[38;5;241m=\u001b[39m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    383\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m:  \u001b[38;5;66;03m# noqa: B902\u001b[39;00m\n",
      "File \u001b[0;32m~/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages/llama_index/graph_stores/nebulagraph.py:275\u001b[0m, in \u001b[0;36mNebulaGraphStore.execute\u001b[0;34m(self, query, param_map)\u001b[0m\n\u001b[1;32m    274\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m result\u001b[38;5;241m.\u001b[39mis_succeeded():\n\u001b[0;32m--> 275\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m    276\u001b[0m         \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mQuery failed. Query: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mquery\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m, Param: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mparam_map\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m    277\u001b[0m         \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mError message: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mresult\u001b[38;5;241m.\u001b[39merror_msg()\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m    278\u001b[0m     )\n\u001b[1;32m    279\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m result\n",
      "\u001b[0;31mValueError\u001b[0m: Query failed. Query: MATCH (p:`entity`)-[r:`relationship`]->(e:`entity`)\nWHERE p.`entity`.`name` == 'Trey Turner' AND r.`relationship` == 'standing ovation'\nSET p.`entity`.`season` = p.`entity`.`season` + 1\nRETURN p.`entity`.`season`, Param: {}Error message: SyntaxError: syntax error near `MAT'",
      "\nThe above exception was the direct cause of the following exception:\n",
      "\u001b[0;31mRetryError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[72], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m response \u001b[38;5;241m=\u001b[39m \u001b[43mkgqe_query_engine\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mquery\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mHow did the standing ovation Trey Turner received change his season?\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m      2\u001b[0m display(Markdown(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m<b>\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mresponse\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m</b>\u001b[39m\u001b[38;5;124m\"\u001b[39m))\n",
      "File \u001b[0;32m~/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages/llama_index/core/base_query_engine.py:30\u001b[0m, in \u001b[0;36mBaseQueryEngine.query\u001b[0;34m(self, str_or_query_bundle)\u001b[0m\n\u001b[1;32m     28\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(str_or_query_bundle, \u001b[38;5;28mstr\u001b[39m):\n\u001b[1;32m     29\u001b[0m     str_or_query_bundle \u001b[38;5;241m=\u001b[39m QueryBundle(str_or_query_bundle)\n\u001b[0;32m---> 30\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_query\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstr_or_query_bundle\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m~/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages/llama_index/query_engine/knowledge_graph_query_engine.py:253\u001b[0m, in \u001b[0;36mKnowledgeGraphQueryEngine._query\u001b[0;34m(self, query_bundle)\u001b[0m\n\u001b[1;32m    249\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Query the graph store.\"\"\"\u001b[39;00m\n\u001b[1;32m    250\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcallback_manager\u001b[38;5;241m.\u001b[39mevent(\n\u001b[1;32m    251\u001b[0m     CBEventType\u001b[38;5;241m.\u001b[39mQUERY, payload\u001b[38;5;241m=\u001b[39m{EventPayload\u001b[38;5;241m.\u001b[39mQUERY_STR: query_bundle\u001b[38;5;241m.\u001b[39mquery_str}\n\u001b[1;32m    252\u001b[0m ) \u001b[38;5;28;01mas\u001b[39;00m query_event:\n\u001b[0;32m--> 253\u001b[0m     nodes: List[NodeWithScore] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_retrieve\u001b[49m\u001b[43m(\u001b[49m\u001b[43mquery_bundle\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    255\u001b[0m     response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_response_synthesizer\u001b[38;5;241m.\u001b[39msynthesize(\n\u001b[1;32m    256\u001b[0m         query\u001b[38;5;241m=\u001b[39mquery_bundle,\n\u001b[1;32m    257\u001b[0m         nodes\u001b[38;5;241m=\u001b[39mnodes,\n\u001b[1;32m    258\u001b[0m     )\n\u001b[1;32m    260\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_verbose:\n",
      "File \u001b[0;32m~/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages/llama_index/query_engine/knowledge_graph_query_engine.py:218\u001b[0m, in \u001b[0;36mKnowledgeGraphQueryEngine._retrieve\u001b[0;34m(self, query_bundle)\u001b[0m\n\u001b[1;32m    211\u001b[0m logger\u001b[38;5;241m.\u001b[39mdebug(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mGraph Store Query:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;132;01m{\u001b[39;00mgraph_store_query\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m    213\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcallback_manager\u001b[38;5;241m.\u001b[39mevent(\n\u001b[1;32m    214\u001b[0m     CBEventType\u001b[38;5;241m.\u001b[39mRETRIEVE,\n\u001b[1;32m    215\u001b[0m     payload\u001b[38;5;241m=\u001b[39m{EventPayload\u001b[38;5;241m.\u001b[39mQUERY_STR: graph_store_query},\n\u001b[1;32m    216\u001b[0m ) \u001b[38;5;28;01mas\u001b[39;00m retrieve_event:\n\u001b[1;32m    217\u001b[0m     \u001b[38;5;66;03m# Get the graph store response\u001b[39;00m\n\u001b[0;32m--> 218\u001b[0m     graph_store_response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgraph_store\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mquery\u001b[49m\u001b[43m(\u001b[49m\u001b[43mquery\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mgraph_store_query\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    219\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_verbose:\n\u001b[1;32m    220\u001b[0m         print_text(\n\u001b[1;32m    221\u001b[0m             \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mGraph Store Response:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;132;01m{\u001b[39;00mgraph_store_response\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m    222\u001b[0m             color\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124myellow\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m    223\u001b[0m         )\n",
      "File \u001b[0;32m~/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages/llama_index/graph_stores/nebulagraph.py:669\u001b[0m, in \u001b[0;36mNebulaGraphStore.query\u001b[0;34m(self, query, param_map)\u001b[0m\n\u001b[1;32m    668\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mquery\u001b[39m(\u001b[38;5;28mself\u001b[39m, query: \u001b[38;5;28mstr\u001b[39m, param_map: Optional[Dict[\u001b[38;5;28mstr\u001b[39m, Any]] \u001b[38;5;241m=\u001b[39m {}) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Any:\n\u001b[0;32m--> 669\u001b[0m     result \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mexecute\u001b[49m\u001b[43m(\u001b[49m\u001b[43mquery\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mparam_map\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    670\u001b[0m     columns \u001b[38;5;241m=\u001b[39m result\u001b[38;5;241m.\u001b[39mkeys()\n\u001b[1;32m    671\u001b[0m     d: Dict[\u001b[38;5;28mstr\u001b[39m, \u001b[38;5;28mlist\u001b[39m] \u001b[38;5;241m=\u001b[39m {}\n",
      "File \u001b[0;32m~/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages/tenacity/__init__.py:289\u001b[0m, in \u001b[0;36mBaseRetrying.wraps.<locals>.wrapped_f\u001b[0;34m(*args, **kw)\u001b[0m\n\u001b[1;32m    287\u001b[0m \u001b[38;5;129m@functools\u001b[39m\u001b[38;5;241m.\u001b[39mwraps(f)\n\u001b[1;32m    288\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mwrapped_f\u001b[39m(\u001b[38;5;241m*\u001b[39margs: t\u001b[38;5;241m.\u001b[39mAny, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkw: t\u001b[38;5;241m.\u001b[39mAny) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m t\u001b[38;5;241m.\u001b[39mAny:\n\u001b[0;32m--> 289\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mf\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkw\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m~/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages/tenacity/__init__.py:379\u001b[0m, in \u001b[0;36mRetrying.__call__\u001b[0;34m(self, fn, *args, **kwargs)\u001b[0m\n\u001b[1;32m    377\u001b[0m retry_state \u001b[38;5;241m=\u001b[39m RetryCallState(retry_object\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m, fn\u001b[38;5;241m=\u001b[39mfn, args\u001b[38;5;241m=\u001b[39margs, kwargs\u001b[38;5;241m=\u001b[39mkwargs)\n\u001b[1;32m    378\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[0;32m--> 379\u001b[0m     do \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43miter\u001b[49m\u001b[43m(\u001b[49m\u001b[43mretry_state\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mretry_state\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    380\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(do, DoAttempt):\n\u001b[1;32m    381\u001b[0m         \u001b[38;5;28;01mtry\u001b[39;00m:\n",
      "File \u001b[0;32m~/miniconda3/envs/llamaindex_nebulagraph_phillies/lib/python3.11/site-packages/tenacity/__init__.py:326\u001b[0m, in \u001b[0;36mBaseRetrying.iter\u001b[0;34m(self, retry_state)\u001b[0m\n\u001b[1;32m    324\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mreraise:\n\u001b[1;32m    325\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m retry_exc\u001b[38;5;241m.\u001b[39mreraise()\n\u001b[0;32m--> 326\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m retry_exc \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mfut\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mexception\u001b[39;00m()\n\u001b[1;32m    328\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mwait:\n\u001b[1;32m    329\u001b[0m     sleep \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mwait(retry_state)\n",
      "\u001b[0;31mRetryError\u001b[0m: RetryError[<Future at 0x317f75710 state=finished raised ValueError>]"
     ]
    }
   ],
   "source": [
    "response = kgqe_query_engine.query(\"How did the standing ovation Trey Turner received change his season?\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c5f64284",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "\u001b[1;3;32mEntities processed: ['season', 'ovation', 'standing', 'Turner', 'Trey', 'Trey Turner', 'change', 'standing ovation']\n",
      "\u001b[0mINFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "\u001b[1;3;32mEntities processed: ['season', 'seasons', 'ovation', 'standing', 'Turner', 'Trey', 'Trey Turner', 'stand', 'change', 'ovations', 'changes', 'standing ovation', 'trey']\n",
      "\u001b[0m\u001b[1;3;34mGraph RAG context:\n",
      "The following are knowledge sequence in max depth 2 in the form of directed graph like:\n",
      "`subject -[predicate]->, object, <-[predicate_next_hop]-, object_next_hop ...` extracted based on key entities as subject:\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: is asking}]-> what happened to Trey Turner{name: what happened to Trey Turner} <-[relationship:{relationship: is asking}]- Trey Turner{name: Trey Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: argued}]-> ball in strike call{name: ball in strike call} <-[relationship:{relationship: argued}]- Trea Turner{name: Trea Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: surpassed}]-> RBI total{name: RBI total} <-[relationship:{relationship: surpassed}]- Trea Turner{name: Trea Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: is familiar with}]-> every baseball fan{name: every baseball fan} <-[relationship:{relationship: is familiar with}]- Trey Turner{name: Trey Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: has three cycles tying}]-> the all-time MLB record{name: the all-time MLB record} <-[relationship:{relationship: has three cycles tying}]- Trey Turner{name: Trey Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: has gotten contracts}]-> from Phillies and Dodgers{name: from Phillies and Dodgers} <-[relationship:{relationship: has gotten contracts}]- Trey Turner{name: Trey Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: has won}]-> World Series{name: World Series} <-[relationship:{relationship: has won}]- Trey Turner{name: Trey Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: is leaving}]-> everyone confused{name: everyone confused} <-[relationship:{relationship: is leaving}]- Trey Turner{name: Trey Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: has been}]-> a silver slugger{name: a silver slugger} <-[relationship:{relationship: has been}]- Trey Turner{name: Trey Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: is}]-> two-time all-star{name: two-time all-star} <-[relationship:{relationship: is}]- Trey Turner{name: Trey Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: had}]-> WILD 2023 Season{name: WILD 2023 Season} <-[relationship:{relationship: had}]- Trea Turner{name: Trea Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: has helped lead}]-> his team to the WBC Championship{name: his team to the WBC Championship} <-[relationship:{relationship: has helped lead}]- Trey Turner{name: Trey Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: is}]-> known speed demon{name: known speed demon} <-[relationship:{relationship: is}]- Trey Turner{name: Trey Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: is}]-> in worst slump of career{name: in worst slump of career} <-[relationship:{relationship: is}]- Trey Turner{name: Trey Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: has tied}]-> all-time MLB record{name: all-time MLB record} <-[relationship:{relationship: has tied}]- Trey Turner{name: Trey Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: is}]-> asking what happened{name: asking what happened} <-[relationship:{relationship: is}]- Trey Turner{name: Trey Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: is currently in}]-> the worst slump of his career{name: the worst slump of his career} <-[relationship:{relationship: is currently in}]- Trey Turner{name: Trey Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: has been}]-> silver slugger{name: silver slugger} <-[relationship:{relationship: has been}]- Trey Turner{name: Trey Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: put glove in front of}]-> ground ball{name: ground ball}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: is}]-> known speed demon{name: known speed demon}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: is}]-> one-time silver slugger{name: one-time silver slugger} <-[relationship:{relationship: is}]- Trey Turner{name: Trey Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: been fighting}]-> own demons{name: own demons}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: is}]-> leaving everyone confused{name: leaving everyone confused}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: is}]-> in worst slump of career{name: in worst slump of career}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: has been}]-> on MLB first and second team{name: on MLB first and second team}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: is}]-> one-time silver slugger{name: one-time silver slugger}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: had}]-> WILD 2023 Season{name: WILD 2023 Season}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: is getting paid}]-> $300 million{name: $300 million} <-[relationship:{relationship: is getting paid}]- Trey Turner{name: Trey Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: has been}]-> nightmare season{name: nightmare season} <-[relationship:{relationship: has been}]- Trey Turner{name: Trey Turner}\n",
      "Trey Turner{name: Trey Turner} -[relationship:{relationship: is}]-> getting paid $300 million{name: getting paid $300 million}\n",
      "\u001b[0mINFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>The standing ovation Trey Turner received did not change his season.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = kg_rag_query_engine.query(\"How did the standing ovation Trey Turner received change his season?\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2d4a6314",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>I'm sorry, but I cannot provide any facts about the current stadium of the Philadelphia Phillies based on the given context information.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = kg_query_engine.query(\"Tell me some facts about the current stadium of Philadelphia Phillies.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "17189425",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>The current stadium of the Philadelphia Phillies is a popular venue for baseball games. It is known for its modern facilities and amenities, providing a great experience for fans. The stadium has a capacity to hold a large number of spectators, allowing for a lively and energetic atmosphere during games. It is also equipped with state-of-the-art technology, including video screens and sound systems, enhancing the overall game-watching experience. The stadium is conveniently located, making it easily accessible for fans attending games.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = kg_keyword_query_engine.query(\"Tell me some facts about the current stadium of Philadelphia Phillies.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a5d84c12",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: f696d792-d9ba-4fa1-bdd5-b78367ee1930: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "> Querying with idx: 2e46e688-dfcc-4b84-8653-7c73756a3c7d: While the noise in the city and national media became louder and louder the s...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "> Querying with idx: 69ba8250-58e9-49a9-9327-b80fc2466ece: His powers were seemingly gone as if they were zapped and taken from him by t...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 778ffd2a-02f2-4bb6-b465-ebb339602383: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "> Querying with idx: 8dbec2a6-46bc-4df7-98cc-c81c5aad2728: At this point in his career, every baseball fan is familiar with the name Tre...\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>I'm sorry, but the given context does not provide any information about the current stadium of the Philadelphia Phillies.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = kg_hybrid_query_engine.query(\"Tell me some facts about the current stadium of Philadelphia Phillies.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d15a779",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>The current stadium of the Philadelphia Phillies is Citizens Bank Park. It has been the team's home stadium since 2004 and is located in the South Philadelphia Sports Complex.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = vector_query_engine.query(\"Tell me some facts about the current stadium of Philadelphia Phillies.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0e4d7c45",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "> No relationships found, returning nodes found by keywords.\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "> No nodes found by keywords, returning empty response.\n",
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>The current stadium of the Philadelphia Phillies is Citizens Bank Park. It has been the team's home stadium since 2004 and is located in the South Philadelphia Sports Complex.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = custom_query_engine.query(\"Tell me some facts about the current stadium of Philadelphia Phillies.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "730b26cd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "\u001b[1;3;33mGraph Store Query:\n",
      "MATCH (s:`entity`)-[:`relationship`]->(p:`entity`)\n",
      "WHERE s.`name` == 'Philadelphia Phillies'\n",
      "RETURN p.`name`\n",
      "\u001b[0m\u001b[1;3;33mGraph Store Response:\n",
      "{'p.name': []}\n",
      "\u001b[0mINFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "\u001b[1;3;32mFinal Response: I'm sorry, but I couldn't find any facts about the current stadium of the Philadelphia Phillies based on the given context information.\n",
      "\u001b[0m"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>I'm sorry, but I couldn't find any facts about the current stadium of the Philadelphia Phillies based on the given context information.</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = kgqe_query_engine.query(\"Tell me some facts about the current stadium of Philadelphia Phillies.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c72af9e4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "\u001b[1;3;32mEntities processed: ['facts', 'current', 'current stadium', 'Philadelphia', 'Philadelphia Phillies', 'stadium', 'Phillies']\n",
      "\u001b[0mINFO:httpx:HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "HTTP Request: POST https://firstaiproject.openai.azure.com//openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-07-01-preview \"HTTP/1.1 200 OK\"\n",
      "\u001b[1;3;32mEntities processed: ['phillies', 'current', 'philadelphia', 'current stadium', 'philadelphia phillies', 'stadium', 'facts']\n",
      "\u001b[0mINFO:llama_index.indices.knowledge_graph.retrievers:> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "INFO:llama_index.indices.knowledge_graph.retrievers:> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n",
      "> No knowledge sequence extracted from entities.\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "<b>Empty Response</b>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "response = kg_rag_query_engine.query(\"Tell me some facts about the current stadium of Philadelphia Phillies.\")\n",
    "display(Markdown(f\"<b>{response}</b>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c565e627",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
